package lxt.service.impl;

import java.util.ArrayList;
import java.util.List;

import lxt.dao.CostFixDao;
import lxt.entity.CostFix;
import lxt.service.CostFixService;
/**
 * 车辆维修service
 * @author Lit
 *
 */
public class CostFixServiceImpl implements CostFixService {
	private CostFixDao costFixDao;
	
	public boolean addCostFix(CostFix costFix) throws Exception {
		this.costFixDao.save(costFix);
		return true;
	}

	public boolean deleteCostFix(String id) throws Exception {
		String[] delId = id.split(",");
		for(int i=0;i<delId.length;i++){
			String idstr = delId[i];
			this.costFixDao.delete(CostFix.class, idstr);
		}
		return true;
	}

	public int loadAllCostFixCount(String truckId, String driverId,
			String fixStation) throws Exception {
		return this.costFixDao.loadAllCostFixCount(truckId, driverId, fixStation);
	}

	public List<CostFix> loadCostFix(String truckId, String driverId,
			String fixStation, int offset, int length) throws Exception {
		List<Object> objects = this.costFixDao.loadAllCostFix(truckId, driverId, fixStation, offset, length);
		List<CostFix> costFixs = new ArrayList<CostFix>();//定义要传出的list
		if(objects.size()>0){
			for(int i=0;i<objects.size();i++){
				Object[] ob = (Object[])objects.get(i);
				CostFix costFix = (CostFix)ob[0];
				costFix.setDriverId((String)ob[1]);
				costFixs.add(costFix);
			}
		}
		return costFixs;
	}

	public CostFix loadCostFixById(String id) throws Exception {
		return (CostFix) this.costFixDao.get(CostFix.class, id);
	}

	public boolean updateCostFix(CostFix costFix) throws Exception {
		this.costFixDao.update(costFix);
		return true;
	}
	/**
	 * get set
	 * @return
	 */
	public CostFixDao getCostFixDao() {
		return costFixDao;
	}

	public void setCostFixDao(CostFixDao costFixDao) {
		this.costFixDao = costFixDao;
	}
	
}
